import [vList,Character,Value,Scope]
import structs/ArrayList

lString : class extends Value { // String is implemented like a type of its own, as it is not evaluated to a list of characters at parse time, but at execution time
    value : String = ""
    valid? := true
    init : func ~withStringWithoutLine(=value)
    init : func ~withStringWithLine(=value,=line)
    
    init : func ~withListWithoutLine(list : vList) {
        for(val in list values) {
            if(val class != Character) {
                valid? = false
            } else {
                value += val as Character value
            }
        }

		if(list values size == 0) { valid? = false }
    }
    
    init : func ~withListWithLine(list : vList, =line) {
        init(list)
    }
    
    toString : func -> String { "\""+value+"\"" }
    equals? : func(other : Value) -> Bool {
        if(other class == This) {
            return (other as This value == this value)
        } else if(other class == vList) {
            return (lString new(other as vList,line) equals?(this)) // Note the recursion ;) 
        } else {
            return false
        }
    }
    
    toList : func -> vList {
        vals := ArrayList<Value> new()
        for(c in value) {
            vals add(Character new(c) as Value)
        }
        vList new(vals,line)
    }
    
    clone : func -> Value {
        lString new(toList() clone() as vList)
    }
    
    evaluate : func(scope : Scope) -> Value {
        toList() as Value
    }
    
}
